﻿<!DOCTYPE html>
<html>
<head>
    <title>收款卡余额变化表</title>
    <script src="/js/header.js"></script>
    <link href="/lib/jquery/jquery-ui.min.css" rel="stylesheet" />
    <script src="/lib/jquery/jquery-ui.min.js"></script>
    <script src="/lib/date/wdatepicker.js"></script>
    <link href="/lib/easyui/default/easyui.css" rel="stylesheet" />
    <script type="text/javascript" src="/lib/easyui/jquery.easyui.min.js"></script>
</head>
<body>
    <div class="data-wrap case" id="container">
        <div class="data-tool clearfix">
            <div class="pull-left form-inline ">
                <a class="btn btn-default btn-sm export ReceiptBalance0002 hide gettext" href="javascript:void(0)" data-title="导出">导出</a>
            </div>

            <div class="pull-right">
                <form class="form-inline" id="formSearch">
                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l gettext">公司名称：</label>
                        <input class="form-control wd150" name="companyName" type="text" autocomplete="off" />
                    </div>

                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l gettext">银行名称：</label>
                        <input class="form-control wd150" name="bankName" type="text" autocomplete="off" />
                    </div>

                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l gettext">银行卡号：</label>
                        <input class="form-control wd150" name="cardNumber" type="text" autocomplete="off" />
                    </div>

                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l gettext">用户名：</label>
                        <input class="form-control wd150" name="cardName" type="text" autocomplete="off" />
                    </div>

                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l gettext">新增时间：</label>
                        <input id="d421" class="Wdate wd175" name="startTime" type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'%y-%M-%d'})" autocomplete="off"/>
                        --<input id="d422" class="Wdate wd175 m5_l" name="endTime" type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'d421\')}'})" autocomplete="off"/>

                    </div>
                    <button type="button" class="btn btn-default btn-sm active gettext" id="btnSearch">搜索</button>
                </form>
            </div>
        </div>
        <div class="data-easyui data-scroll">
            <div class="data-view">
                <div class="data-div-view table-responsive">
                    <table class="table" id="receiptAdjustBalance"></table>
                </div>
            </div>
        </div>
    </div>
    <script src="/js/page/receiptadjustbalance.js?v=201903201544"></script>
    <script type="text/javascript">
        var pageSize = 50;
        $(function () {
            $("input[name='startTime']").val(FlashPay.Util.GetDateStr(0));
            FlashPay.UI.DataAutoHeight();
            doSearch();
            setTime();
            $("body").keydown(function (event) {
                if (event.keyCode == "13") {
                    doSearch();
                }
            });
            $("#btnSearch").click(function () {
                FlashPay.UI.DoSearch();
            });

            FlashPay.Util.Ajax({
                type: "POST",
                url: "/payment/AdjustBalanceExportAuth",
                dataType: "json",
                contentType: "application/json",
                success: function (res) {
                    if (res.success) {
                        if (res.data.receiptAdjustBalance == 'ReceiptBalance0002') {
                            $("a.ReceiptBalance0002").removeClass("hide");
                        } else {
                            $("a.ReceiptBalance0002").remove();
                        }
                    }
                }
            });

            FlashPay.Util.Language();
        });

        function setTime() {
            $("input[name='startTime']").val(FlashPay.Util.GetDateStr(0) + " 00:00:00");
            $("input[name='endTime']").val(FlashPay.Util.GetDateStr(0) + " 23:59:59");;
        }

    $(".export").click(function () {

            var query = {};

            var companyName = $("input[name='companyName']").val();
            if (!FlashPay.Util.isNullOrEmptySpance(companyName)) {
                query.companyName = companyName;
            }

            var bankName = $("input[name='bankName']").val();
            if (!FlashPay.Util.isNullOrEmptySpance(bankName)) {
                query.bankName = bankName;
            }

            var cardNumber = $("input[name='cardNumber']").val();
            if (!FlashPay.Util.isNullOrEmptySpance(cardNumber)) {
                query.cardNumber = cardNumber;
            }

            var cardName = $("input[name='cardName']").val();
            if (!FlashPay.Util.isNullOrEmptySpance(cardName)) {
                query.cardName = cardName;
            }

            var startTime = $("input[name='startTime']").val();
            if (!FlashPay.Util.isNullOrEmptySpance(startTime)) {
                query.startTime = startTime;
            }

            var endTime = $("input[name='endTime']").val();
            if (!FlashPay.Util.isNullOrEmptySpance(endTime)) {
                query.endTime = endTime;
            }

            query.adjustStatus = 1;
            FlashPay.UI.Confirm({
                content: "下载余额变化需要花费大量时间,确认要下载吗？",
                ok: function () {
                    var cover = FlashPay.UI.Mask({
                        obj: $("body"),
                        opacity: 0.5
                    });

                    FlashPay.Util.Ajax({
                        url: '/Payment/AdjustBalanceExport',
                        type: 'POST',
                        data: { query: query },
                        success: function (response) {
                            if (response.success) {
                                cover.Remove();

                                if (response.data != null && response.data.length > 0) {
                                    var body = '<table>';

                                    body += '<tr>';
                                    body += '<td>公司名称</td>';
                                    body += '<td>银行名称</td>';
                                    body += '<td>用户名</td>';
                                    body += '<td>银行卡号</td>';
                                    body += '<td>金额</td>';
                                    body += '<td>余额变化前</td>';
                                    body += '<td>余额变化后</td>';
                                    body += '<td>新增者</td>';
                                    body += '<td>类别</td>';
                                    body += '<td>新增时间</td>';
                                    body += '<td>订单号</td>';
                                    body += '<td>新增说明</td>';
                                    body += '</tr>';

                                    $.each(response.data, function (i, item) {
                                        body += '<tr>';
                                        body += '<td>' + item.companyName + '</td>';
                                        body += '<td>' + item.bankName + '</td>';
                                        body += '<td>' + item.cardName + '</td>';
                                        body += '<td>' + item.cardNumber + '</td>';
                                        body += '<td>' + item.amount + '</td>';
                                        body += '<td>' + item.beforeBalance + '</td>';
                                        body += '<td>' + item.afterBalance + '</td>';
                                        body += '<td>' + item.createName + '</td>';
                                        body += '<td>' + item.adjustStatusText + '</td>';
                                        body += '<td>' + item.createDBDate + '</td>';
                                        body += '<td>' + item.orderNo + '</td>';
                                        body += '<td>' + item.createRemark + '</td>';
                                        body += '</tr>';
                                    });

                                    body += '</table>';

                                    var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>";
                                    excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">';
                                    excelFile += "<head>";
                                    excelFile += "<!--[if gte mso 9]>";
                                    excelFile += "<xml>";
                                    excelFile += "<x:ExcelWorkbook>";
                                    excelFile += "<x:ExcelWorksheets>";
                                    excelFile += "<x:ExcelWorksheet>";
                                    excelFile += "<x:Name>";
                                    excelFile += "Sheet1";
                                    excelFile += "</x:Name>";
                                    excelFile += "<x:WorksheetOptions>";
                                    excelFile += "<x:DisplayGridlines/>";
                                    excelFile += "</x:WorksheetOptions>";
                                    excelFile += "</x:ExcelWorksheet>";
                                    excelFile += "</x:ExcelWorksheets>";
                                    excelFile += "</x:ExcelWorkbook>";
                                    excelFile += "</xml>";
                                    excelFile += "<![endif]-->";
                                    excelFile += "</head>";
                                    excelFile += "<body>";
                                    excelFile += body;
                                    excelFile += "</body>";
                                    excelFile += "</html>";

                                    var uri = window.URL.createObjectURL(new Blob([excelFile], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }));
                                    var link = document.createElement("a");
                                    link.href = uri;

                                    link.style = "visibility:hidden";
                                    link.download = response.statusCode + ".xlsx";

                                    document.body.appendChild(link);
                                    link.click();
                                    document.body.removeChild(link);
                                }
                                else {
                                    cover.Remove();
                                    FlashPay.UI.Tip_short_warning("暂无记录");
                                }

                            } else {
                                cover.Remove();
                                FlashPay.UI.Tip_short_warning("操作失败！" + response.errorMessage);
                            }
                        },
                        error: function (json) {
                            cover.Remove();
                            FlashPay.UI.Tip_warning("操作失败！请查看网络，请重试。");
                        }
                    });
                }
            });
    });
    </script>
</body>
</html>